package cn.lizheng.web;

import cn.lizheng.dao.AdmininfoDAO;
import cn.lizheng.dao.AdmininfoDAOImpl;
import cn.lizheng.pojo.Admininfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/admininfopage")
public class AdmininfoPageServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String p=req.getParameter("p");//接受页码
        int pageNum=1;//默认第一页
        if (p!=null){
            pageNum=Integer.parseInt(p);
        }
        int pagesize=5;//每页显示条数
        AdmininfoDAO dao= new AdmininfoDAOImpl();
        //调用分页查询
        List<Admininfo> aList=dao.getpage(pageNum,pagesize);
        req.setAttribute("adminList",aList);//绑定参数
        int nums=dao.count();//查询总数
        //计算总页数
        int totalPage=(nums%pagesize==0)?(nums/pagesize):(nums/pagesize+1);
        //当前页
        req.setAttribute("cp",pageNum);
        //总页数
        req.setAttribute("tp",totalPage);
        req.getRequestDispatcher("admininfoPage.jsp").forward(req,resp);//页面分发
    }
}
